package calao.client.ui;

import com.google.gwt.user.client.ui.TextBox;

public class RegexTextBox 
extends TextBox
implements Validatable
{
	
	final String pattern;
	
	public RegexTextBox(String pattern)
	{
		this.pattern = pattern;
	}

	public void validate() throws InvalidInputException 
	{
		String text = getText();
		if (text==null) text = "";
		if (!text.matches(pattern)) {
			addStyleName(Styles.INVALID);
			throw new InvalidInputException();
		}
		removeStyleName(Styles.INVALID);
	}

}
